<?php session_start(); ?>
<!DOCTYPE html>
<html>
    <head>
        <link rel="stylesheet" type="text/css" href="../css/projectstyle.css">
        <title></title>
        <meta charset="UTF-8">
    </head>
    <body>
        <?php
        if ($_SERVER["REQUEST_METHOD"] == "POST") {
            $condb = mysqli_connect("localhost", "root", "password", "PROJECT");
            
            if (isset($_POST['course'])) {
                $courseid = $_POST['course'];

                // sets variables to insert into database





                if (mysqli_connect_errno()) {
                    echo "connection failed " . mysqli_connect_error();
                }

                $select = "SELECT COURSE_ID,COURSE_NAME ,START_DATE, STOP_DATE FROM COURSE WHERE COURSE_ID='$courseid'";

                $result = mysqli_query($condb, $select);

                while ($row = mysqli_fetch_array($result)) {
                    $course_id = $row['COURSE_ID'];
                    $course_name = $row['COURSE_NAME'];
                    $startdate = $row['START_DATE'];
                    $stopdate = $row['STOP_DATE'];
                }
            }
        } else {
            header("location:../error.php");
        }
        ?>



        <p id="instructions" class="instructions">Ändra i formuläret!</p>
        <div class="wrap">
            <div class="frmc">
                <form id ="frmc" name ="frmc" action="updatecourse.php" method="post"><!--form used to add course-->


                    <p>Kurskod: <input type="text" name ="newcourseId" required value="<?php echo $course_id; ?>"></input></p>
                    <p>Startdatum: <input type="date"name = "startDate" required value="<?php echo $startdate; ?>"></input></p>

                    <p>Slutdatum: <input type="date"name = "stopDate" required value="<?php echo $stopdate; ?>"></input></p>
                    
                    <!-- <p>Kursnamn: <input type="text" name = "courseName" required value="<?php echo $course_name; ?>"></input></p>-->
                     <textarea rows="4" cols="25" name = "courseName"><?php echo $course_name; ?></textarea><br/>
                    <input type="hidden" value="<?php echo $course_id; ?>" name="courseId">
                    <input type="submit" value="spara ändringar">
                </form>  
                <button onclick="location.href = '../courses/availablecourses.php';" id="discardButton" >Avbryt</button>
            </div>
        </div>
    </body>